<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8"/>
    <title>51问医生</title>
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <script src="{{url('/js/jquery.min.js')}}" type="text/javascript"></script>
    <link rel="stylesheet" href="{{url('new/css/common.css')}}" />

    <script src="{{url('new/js/doctor_list.js')}}"></script>
    <link rel="stylesheet" href="{{url('new/css/usercenter-set.css')}}" />
    <script src="{{url('js/lCalendar.js')}}"></script>
    <link rel="stylesheet" href="{{url('css/lCalendar.css')}}">

    <link rel="stylesheet" href="{{url('/css/foxui.css')}}">
    <link rel="stylesheet" href="{{url('/css/foxui.theme.css')}}">
    <script type="text/javascript" src="{{url('js/foxui.js')}}"></script>
</head>
<body>
<div class="register">
    <p class="regWord">完善患者信息才可预约(仅医生可见)</p>
    <div class="reg-port">
        <span class="lable">姓名</span>
        <input type="text" id="realname" value="@if($userinfo){{$userinfo->realname}}@endif" placeholder="请输入患者姓名（必填）" />
        <span class="svgclear" ></span>
    </div>

    <div class="reg-port">
        <span class="lable">手机</span>
        <input type="text" id="phone" value="@if($userinfo){{$userinfo->phone}}@endif" placeholder="请输入您的手机（必填）" />
        <span class="svgclear" ></span>
    </div>

    <p class="reg-port item">
        <span class="lable">性别</span>
        <span class="sex @if(!$userinfo || ($userinfo && $userinfo->sexual == 0))cur @endif" id="girl">女</span>
        <span  class="sex @if($userinfo && $userinfo->sexual == 1)cur @endif" id="man">男</span>
        <input type="hidden" id="sex" value="@if($userinfo){{$userinfo->sexual}}@endif" />
    </p>
    <p class="reg-port item">
        <span class="lable">生日</span>
        <input type="text" id="birthday" value="@if($userinfo)<?php echo date('Y-m-d',strtotime($userinfo->birthday)); ?>@endif" placeholder="请选择生日" readonly="" name="input_date" />
    </p>
    <a href="javascript:;">
        <div class="btn-submit  ax-bareBtn ">
            <button type="submit" id="btn_send">
                {{--<i class="ax-pay-loading"></i>提交</button>--}}
                <i class="ax-pay-loading"></i>提交</button>
        </div>
    </a>
</div>
<script>
    var calendar = new lCalendar();
    calendar.init({
        'trigger': '#birthday',
        'type': 'date'
    });

    $(function(){
        $("#birthday").focus(function(){
            document.activeElement.blur();
        });

        $('#girl').click(function(){
            var sex = $('#sex').val();
            if(parseInt(sex) == 1){
                $('#girl').addClass('cur');
                $('#man').removeClass('cur');
                $('#sex').val('0');
            }
        });

        $('#man').click(function(){
            var sex = $('#sex').val();
            if(parseInt(sex) == 0) {
                $('#man').addClass('cur');
                $('#girl').removeClass('cur');
                $('#sex').val('1');
            }
        });

        function isPhoneNo(phone) {
            var pattern = /^1[34578]\d{9}$/;
            return pattern.test(phone);
        }

        $('#btn_send').click(function(){
            var sex      = $('#sex').val();
            var realname = $('#realname').val();
            var phone    = $('#phone').val();
            var birthday = $('#birthday').val();

            if(realname.trim().length == 0){
                FoxUI.toast.show('请输入您的姓名',true);
            }else if(!isPhoneNo(phone)){
                FoxUI.toast.show('手机号码格式不正确',true);
            }else{
                $.ajax({
                    type:"post",
                    url:'{{route('Api.User.setUserInfo')}}',
                    dataType:"json",
                    data:{"realname":realname,"sex":sex,"phone":phone,"birthday":birthday},
                    success:function(obj){
                        if(obj.level == "success"){
                            FoxUI.alert(obj.message,'提示语',function(){
                                window.location.href="{{route('M.Home.newUserCenter')}}";
                            });
                        }
                    },
                    error:function(obj){
                        var datajson = obj.responseJSON;
                        FoxUI.alert(datajson.message,'提示语');
                    }
                });
            }
        });
    });
</script>
</body>
</html>